package pl.mchaniewski.ryneczek.utilities;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.faces.context.FacesContext;

public class I18nUtil {
    private static final String BUNDLE_LOCATION = "pl.mchaniewski.ryneczek.i18n.localizedMessages";

    public static String getLocalizedMessage(String key) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            Locale locale = context.getViewRoot().getLocale();

            ResourceBundle rs = ResourceBundle.getBundle(BUNDLE_LOCATION,
                    locale);

            return rs.getString(key);
        } catch (Exception ex) {
            return null;
        }
    }
}
